//
//  PRODUCTION.m
//  Khmer media
//
//  Created by Rainseylong on 2/12/13.
//  Copyright (c) 2013 imer. All rights reserved.
//

#import "PRODUCTION.h"
#import "Apiconnection.h"

static NSString * const AllProduction =@"Productions/productionsJson/?encryptKey=g2cSBfct1uaGThCKWcHejter7eqlEXz3P14V7JewTao=&phoneModel=&menufacturer=samsung&phoneNumber=&osVersion=4.0.3&deviceID=IML74K";

@implementation PRODUCTION


@synthesize productionName= _productionName;
@synthesize productionNameRendered= _productionNameRendered;
@synthesize productionId= _productionId;
@synthesize dateUpdated=_dateUpdated;
@synthesize dateCreated=_dateCreated;

- (id)initWithAttributes:(NSDictionary *)attributes
{
    self = [super init];
    if (!self) {
        return nil;
    }
    
    _productionName = [attributes valueForKey:@"productionName"];
    _productionNameRendered = [attributes valueForKey:@"productionNameRendered"];
    _productionId = [attributes valueForKey:@"productionId"];
    _dateUpdated = [attributes valueForKey:@"dateUpdated"];
    _dateCreated = [attributes valueForKey:@"dateCreated"];
    
    return self;
}

+ (void)convertProductionToOBjectWithBlock:(void (^)(NSArray *productionData, NSError *error))block
{    
    [[Apiconnection sharedClient] getPath:AllProduction parameters:Nil success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         NSMutableArray *tempDic=[responseObject valueForKey:@"responseBody"];
         NSMutableArray *mutablePosts = [NSMutableArray arrayWithCapacity:tempDic.count];
         
         for (int i=0;i < tempDic.count;i++) {
             
             PRODUCTION *post = [[PRODUCTION alloc] initWithAttributes:[tempDic objectAtIndex:i]];
             [mutablePosts addObject:post];
         }
         
         if (block) {
             block([NSArray arrayWithArray:mutablePosts], nil);
         }
         
     } failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         if (block) {
             NSLog(@"error %@",error);
             block([NSArray array], error);
         }
     }];
}

@end
